package com.xoa.service.hr.socialRelations;

import com.xoa.dao.common.HrCodeMapper;
import com.xoa.dao.hr.socialRelations.SocialRelationsMapper;
import com.xoa.dao.users.UsersMapper;
import com.xoa.model.common.HrCode;
import com.xoa.model.common.HrCodeExample;
import com.xoa.model.enclosure.Attachment;
import com.xoa.model.hr.socialRelations.SocialRelations;
import com.xoa.model.hr.socialRelations.SocialRelationsExample;
import com.xoa.model.hr.socialRelations.SocialRelationsResult;
import com.xoa.model.hr.socialRelations.SocialRelationsWithBLOBs;
import com.xoa.model.users.Users;
import com.xoa.util.DateFormat;
import com.xoa.util.ExcelUtil;
import com.xoa.util.GetAttachmentListUtil;
import com.xoa.util.ToJson;
import com.xoa.util.common.StringUtils;
import com.xoa.util.common.log.FileUtils;
import com.xoa.util.common.wrapper.BaseWrapper;
import com.xoa.util.page.PageParams;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * @program: xoa
 * @description: 社会关系
 * @author: xiaomeng.Yu
 * @create: 2018-07-09 15:30
 **/

@Service
public class SocialRelationsService {

    private static final String RELATIONSHIP="HR_STAFF_RELATIVES";
    private static final String POLITICAL_OUTLOOK="STAFF_POLITICAL_STATUS";

    @Autowired
    SocialRelationsMapper socialRelationsMapper;

    @Autowired
    UsersMapper usersMapper;

    @Resource
    HrCodeMapper hrCodeMapper;

    /**
     * @Description: 保存
     * @Param: [SocialRelatiosn]
     * @return: com.xoa.util.common.wrapper.BaseWrapper
     * @Author: xiaomeng.Yu
     * @Date: 2018/7/9
     */
    public BaseWrapper saveSocialRelation(SocialRelationsWithBLOBs socialRelations){
        BaseWrapper baseWrapper = new BaseWrapper();
        String substring="";
        /*去逗号*/
        if(!StringUtils.checkNull(socialRelations.getStaffRole())){
            String userId = socialRelations.getStaffRole();
            if (userId.contains(",")) {
                substring = userId.substring(0, userId.length() - 1);
                socialRelations.setStaffRole(substring);
            }

            socialRelations.setLastmodifyTime(new Date());
            SocialRelationsExample socialRelationsExample=new SocialRelationsExample();
            SocialRelationsExample.Criteria criteria = socialRelationsExample.createCriteria();
            criteria.andStaffNameEqualTo(substring);
            List<SocialRelationsWithBLOBs> socialRelationsWithBLOBsList = socialRelationsMapper.selectByExampleWithBLOBs(socialRelationsExample);
            int i=0;
            /*用户存在*/
            if (socialRelationsWithBLOBsList != null) {
                if (socialRelationsWithBLOBsList.size() > 0) {
                    socialRelations.setRegisterTime(socialRelationsWithBLOBsList.get(0).getRegisterTime());
                    socialRelations.setSocialRelId(socialRelationsWithBLOBsList.get(0).getSocialRelId());
                    i=socialRelationsMapper.updateByPrimaryKeyWithBLOBs(socialRelations);
                }else{
                    socialRelations.setRegisterTime(new Date());
                    i= socialRelationsMapper.insert(socialRelations);
                }
            }else{
                socialRelations.setRegisterTime(new Date());
                i =  socialRelationsMapper.insert(socialRelations);

            }
            if (i > 0) {
                baseWrapper.setFlag(true);
                baseWrapper.setStatus(true);
                baseWrapper.setMsg("新建成功");
            }
        }

        return baseWrapper;
    }

    /** 
    * @Description: 查询
    * @Param: [] 
    * @return: com.xoa.util.common.wrapper.BaseWrapper 
    * @Author: xiaomeng.Yu
    * @Date: 2018/7/9 
    */ 
    public BaseWrapper getSociaRelation(HttpServletRequest request,Integer page,Integer pageSize,boolean userFlag,String staffRole){
        BaseWrapper baseWrapper = new BaseWrapper();
        String  sqlType = "xoa" + (String) request.getSession().getAttribute(
                "loginDateSouse");
        List<SocialRelationsWithBLOBs> socialRelationsWithBLOBss=new ArrayList<>();
        PageParams pageParams=new PageParams();
        pageParams.setUseFlag(userFlag);
        pageParams.setPage(page);
        pageParams.setPageSize(pageSize);
        Map<String,Object> map=new HashMap<>();
        map.put("pageParams",pageParams);
        if(!StringUtils.checkNull(staffRole)){
            map.put("staffRole", staffRole.split(","));
        }
        /*分页*/
        socialRelationsWithBLOBss = socialRelationsMapper.getSocialRelationsList(map);
        List<SocialRelationsWithBLOBs> params = socialRelationsMapper.selectByPrimaryKey();
        baseWrapper.setData(socialRelationsWithBLOBss);
        baseWrapper.setTotleNum(params.size());
        return baseWrapper;
    }

    /**
    * @Description: 详情页
    * @Param: []common.wrapper.BaseWrapper
    * @Author: xiaomeng.Yu
    * @Date: 2018/7/10
    */
    public BaseWrapper getSociaRelationById(HttpServletRequest request, Integer socialRelId){
        BaseWrapper baseWrapper = new BaseWrapper();
        String  sqlType = "xoa" + (String) request.getSession().getAttribute(
                "loginDateSouse");
        SocialRelationsWithBLOBs socialRelationsWithBLOBs =  socialRelationsMapper.selectById(socialRelId);
        /*附件*/
        List<Attachment> attachments = GetAttachmentListUtil.returnAttachment(socialRelationsWithBLOBs.getAttachmentName(), socialRelationsWithBLOBs.getAttachmentId(), sqlType, GetAttachmentListUtil.MODULE_HR);
        socialRelationsWithBLOBs.setAttachmentList(attachments);
        baseWrapper.setData(socialRelationsWithBLOBs);
        return baseWrapper;
    }

    /**
     * 根据条件查询
     * @param socialRelId
     * @return
     */
    public BaseWrapper getSociaRelationByIdList(HttpServletRequest request,Integer page,Integer pageSize,boolean userFlag,SocialRelationsWithBLOBs socialRelId){

        BaseWrapper baseWrapper = new BaseWrapper();
        String[] userIds = null;
        if(!StringUtils.checkNull(socialRelId.getStaffRole())){
            userIds = socialRelId.getStaffRole().split(",");
            socialRelId.setUserIds(userIds);
        }
        String  sqlType = "xoa" + (String) request.getSession().getAttribute(
                "loginDateSouse");
        List<SocialRelationsWithBLOBs> socialRelationsResults=new ArrayList<>();
        PageParams pageParams=new PageParams();
        pageParams.setUseFlag(userFlag);
        pageParams.setPage(page);
        pageParams.setPageSize(pageSize);

        Map<String,Object> map=new HashMap<>();
        map.put("staffRole",userIds);
        map.put("staffName",socialRelId.getStaffName());
        map.put("relationship",socialRelId.getRelationship());
        map.put("occupation",socialRelId.getOccupation());
        map.put("workCompany",socialRelId.getWorkCompany());
        map.put("pageParams",pageParams);

        Map<String,Object> mapList=new HashMap<>();
        mapList.put("staffRole",userIds);
        mapList.put("staffName",socialRelId.getStaffName());
        mapList.put("relationship",socialRelId.getRelationship());
        mapList.put("occupation",socialRelId.getOccupation());
        mapList.put("workCompany",socialRelId.getWorkCompany());
        socialRelationsResults = socialRelationsMapper.selectByIdList(map);
        List<SocialRelationsWithBLOBs> params = socialRelationsMapper.selectByIdList(mapList);
        baseWrapper.setData(socialRelationsResults);
        baseWrapper.setTotleNum(params.size());
        return baseWrapper;
    }

    /**
     * 修改
     * @param socialRelId
     * @return
     */
    public BaseWrapper updateSociaRelation(SocialRelationsWithBLOBs socialRelId){
        BaseWrapper baseWrapper = new BaseWrapper();

        /*用户存在*/
        if (socialRelId !=null){
            if (socialRelId.getSocialRelId() == null || socialRelId.getSocialRelId() == 0){
                baseWrapper.setMsg("参数错误");
                return baseWrapper;
            }else {
                socialRelId.setLastmodifyTime(new Date());
               SocialRelationsWithBLOBs socialRelationsWithBLOBs = socialRelationsMapper.selectById(socialRelId.getSocialRelId());
               /*用户登记时间存在*/
               if (socialRelationsWithBLOBs!= null){
                   socialRelId.setRegisterTime(socialRelationsWithBLOBs.getRegisterTime());
               }
                String userId = socialRelId.getStaffRole();
                String substring="";
                if (userId.contains(",")) {
                    substring = userId.substring(0, userId.length() - 1);
                    socialRelId.setStaffRole(substring);
                }
                int params = socialRelationsMapper.updateByPrimaryKeyWithBLOBs(socialRelId);
                if (params > 0) {
                    baseWrapper.setFlag(true);
                    baseWrapper.setMsg("修改成功");
                    baseWrapper.setStatus(true);
                }
            }
        }
        return baseWrapper;
    }

    /**
     * 删除
     * @param socialRelId
     * @return
     */
    public BaseWrapper deleteSocialRelations(Integer[] socialRelId){
        BaseWrapper baseWrapper = new BaseWrapper();
        /*单选*/
        if(socialRelId.length==1){
            int params = socialRelationsMapper.deleteByPrimaryKey(socialRelId[0]);
            if (params>0){
                baseWrapper.setStatus(true);
                baseWrapper.setFlag(true);
                baseWrapper.setMsg("删除成功");
            }
        }
        /*多选*/
        if(socialRelId.length>0){
            int param = socialRelationsMapper.deleteByPrimaryKeyByIdList(socialRelId);
            if (param>0){
                baseWrapper.setStatus(true);
                baseWrapper.setFlag(true);
                baseWrapper.setMsg("删除成功");
            }
        }
        return baseWrapper;
    }

    /**
     * 导出
     * @return
     */
    public void exportSocialRelations(HttpServletRequest request, HttpServletResponse response, SocialRelationsWithBLOBs socialRelations){
        try {
            Map<String, Object> map = new HashMap<>();
            map.put("socialRelId",socialRelations.getSocialRelId());
            map.put("staffRole",socialRelations.getStaffRole());
            map.put("staffName",socialRelations.getStaffName());
            map.put("relationship",socialRelations.getRelationship());
            map.put("birthDate",socialRelations.getBirthDate());
            map.put("politicalOutlook",socialRelations.getPoliticalOutlook());
            map.put("occupation",socialRelations.getOccupation());
            map.put("post",socialRelations.getPost());
            map.put("phone",socialRelations.getPhone());
            map.put("telephone",socialRelations.getTelephone());
            map.put("phoneCall",socialRelations.getPhoneCall());
            map.put("workCompany",socialRelations.getWorkCompany());
            map.put("companyAddress",socialRelations.getCompanyAddress());
            map.put("homeAddress",socialRelations.getHomeAddress());
            map.put("remarks",socialRelations.getRemarks());

            List<SocialRelationsWithBLOBs> socialRelationss = socialRelationsMapper.socialRelationsResult(map);
            for(SocialRelationsWithBLOBs socialRelationsWithBLOBs:socialRelationss){
                socialRelationsWithBLOBs.setStaffRole(socialRelationsWithBLOBs.getUserName());
            }
            HSSFWorkbook workbooks = new HSSFWorkbook();
            HSSFCellStyle style = workbooks.createCellStyle();
            style.setAlignment(HorizontalAlignment.CENTER);
            style.setVerticalAlignment(VerticalAlignment.CENTER);
            // 创建一个字体样式
            HSSFFont font = workbooks.createFont();
            font.setFontHeightInPoints((short)16);
            font.setBold(true);
            style.setFont(font);
            HSSFSheet sheet = workbooks.createSheet("社会关系信息导出");
            sheet.setDefaultColumnWidth(25);
            sheet.setDefaultRowHeightInPoints(25);
            CellRangeAddress cellRangeAddress = new CellRangeAddress(0, 0, 0, 14);
            sheet.addMergedRegion(cellRangeAddress);
            HSSFRow rowTitle = sheet.createRow(0);
            HSSFCell cellTitle = rowTitle.createCell(0);
            // 为标题设置背景颜色
            style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
            style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.index);
            cellTitle.setCellValue("社会关系信息导出");
            cellTitle.setCellStyle(style);
            String[] secondTitles = {"序号", "单位员工", "成员姓名", "与本人关系", "出生日期", "政治面貌", "职业", "担任职务", "联系电话(个人)", "联系电话(家庭)",
                    "联系电话(单位)", "工作单位", "单位地址", "家庭住址", "备注"
            };
            HSSFWorkbook workbook2 = ExcelUtil.makeSecondHead(workbooks, secondTitles);
            String[] beanProperty = {"socialRelId", "staffRole", "staffName", "relativeName", "birthDate", "politicalOutlookName", "occupation", "post", "phone", "telephone", "phoneCall", "workCompany", "companyAddress","homeAddress", "remarks"};
            HSSFWorkbook workbook = ExcelUtil.exportExcelData(workbook2, socialRelationss, beanProperty);
            ServletOutputStream out = response.getOutputStream();
            String filename = "社会关系信息导出.xls"; //考虑多语言
            filename = FileUtils.encodeDownloadFilename(filename,
                    request.getHeader("user-agent"));
            response.setContentType("application/vnd.ms-excel");
            response.setHeader("content-disposition",
                    "attachment;filename=" + filename);
            workbook.write(out);
            out.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 导入
     * @return
     */
    public BaseWrapper importSocialRelations(MultipartFile file) throws IOException {
        BaseWrapper baseWrapper = new BaseWrapper();
        //读取当前配置
        ResourceBundle rb = ResourceBundle.getBundle("upload");
        String osName = System.getProperty("os.name");
        StringBuffer path = new StringBuffer();
             StringBuffer buffer=new StringBuffer();
        if(osName.toLowerCase().startsWith("win")){
            //sb=sb.append(rb.getString("upload.win"));
            //判断路径是否是相对路径，如果是的话，加上运行的路径
            String uploadPath = rb.getString("upload.win");
            if(uploadPath.indexOf(":")==-1){
                //获取运行时的路径
                String basePath = this.getClass().getClassLoader().getResource(".").getPath()+ File.pathSeparator;
                //获取截取后的路径
                String str2 = "";
                if(basePath.indexOf("/xoa")!=-1){
                    //获取字符串的长度
                    int length = basePath.length();
                    //返回指定字符在此字符串中第一次出现处的索引
                    int index = basePath.indexOf("/xoa");
                    //从指定位置开始到指定位置结束截取字符串
                    str2=basePath.substring(0,index);
                }
                path = path.append(str2 + "/xoa");
            }
            path.append(uploadPath);
            buffer=buffer.append(rb.getString("upload.win"));
        }else{
            path=path.append(rb.getString("upload.linux"));
            buffer=buffer.append(rb.getString("upload.linux"));
        }
        int success=0;
        // 判断是否为空文件
        if (file.isEmpty()) {
            /*json.setMsg("请上传文件！");
            json.setFlag(1);
            return json;*/
        } else {
            String fileName = file.getOriginalFilename();
            if (fileName.endsWith(".xls") || fileName.endsWith(".xlsx")) {
                String uuid = UUID.randomUUID().toString().replaceAll("-", "");
                int pos = fileName.indexOf(".");
                String extName = fileName.substring(pos);
                String newFileName = uuid + extName;
                File dest = new File(path.toString(), newFileName);
                file.transferTo(dest);
                // 将文件上传成功后进行读取文件
                // 进行读取的路径
                String readPath = path.append(System.getProperty("file.separator")).append(newFileName).toString();

                InputStream is = new FileInputStream(readPath);
                HSSFWorkbook hssfWorkbook = new HSSFWorkbook(is);
                SocialRelationsWithBLOBs socialRelations = null;
                // 循环工作表Sheet
                for (int numSheet = 0; numSheet < hssfWorkbook.getNumberOfSheets(); numSheet++) {
                    HSSFSheet hssfSheet = hssfWorkbook.getSheetAt(numSheet);
                    if (hssfSheet == null) {
                        continue;
                    }
                    // 循环行Row
                    for (int rowNum = 4; rowNum <= hssfSheet.getLastRowNum(); rowNum++) {
                        HSSFRow hssfRow = hssfSheet.getRow(rowNum);
                        if (hssfRow != null) {
                            socialRelations = new SocialRelationsWithBLOBs();
                            HSSFCell staffRole = hssfRow.getCell(0);
                            HSSFCell staffName = hssfRow.getCell(1);
                            HSSFCell relativeName = hssfRow.getCell(2);
                            HSSFCell birthDate = hssfRow.getCell(3);
                            HSSFCell politicalOutlook = hssfRow.getCell(4);
                            HSSFCell occupation = hssfRow.getCell(5);
                            HSSFCell post = hssfRow.getCell(6);
                            HSSFCell phone = hssfRow.getCell(7);
                            HSSFCell telephone = hssfRow.getCell(8);
                            HSSFCell phoneCall = hssfRow.getCell(9);
                            HSSFCell workCompany = hssfRow.getCell(10);
                            HSSFCell companyAddress = hssfRow.getCell(11);
                            HSSFCell homeAddress = hssfRow.getCell(12);
                            HSSFCell remark = hssfRow.getCell(13);
                            if (staffRole!=null){
                                Users userByName = usersMapper.getUserByName(staffRole.getStringCellValue());
                                if (userByName != null) {
                                    socialRelations.setStaffRole(userByName.getUserId());
                                }else{
                                    socialRelations.setStaffRole("");
                                }
                            }
                            if (staffName != null){
                                socialRelations.setStaffName(staffName.getStringCellValue());
                            }
                            if(politicalOutlook!=null){
                                politicalOutlook.setCellType(CellType.STRING);
                                socialRelations.setPoliticalOutlook(politicalOutlook.getStringCellValue());
                            }
                           if (relativeName!= null) {
                               relativeName.setCellType(CellType.STRING);
                               socialRelations.setRelationship(relativeName.getStringCellValue());
                           }
                            if(birthDate != null){
                                try {
                                   //SimpleDateFormat ft = new SimpleDateFormat("yyyy-MM-dd");
                                   // SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd");
                                    Date st = new SimpleDateFormat("yyyy-MM-dd").parse(birthDate.getStringCellValue());

                               //     String format = simpleDateFormat.format(birthDate.getStringCellValue());
                                    //birthDate.setCellType(CellType.STRING);
                                    //System.out.println(st);
                                    socialRelations.setBirthDates(st);
                                } catch (ParseException e) {
                                    e.printStackTrace();
                                }

                            }
                            if(occupation != null){
                                socialRelations.setOccupation(occupation.getStringCellValue());
                            }
                            if (post != null){
                                socialRelations.setPost(post.getStringCellValue());
                            }
                           if (phone!=null){
                               phone.setCellType(CellType.STRING);
                               socialRelations.setPhone(phone.getStringCellValue());
                           }

                           if (telephone != null){
                               telephone.setCellType(CellType.STRING);
                               socialRelations.setTelephone(telephone.getStringCellValue());
                           }
                           if (phoneCall != null){
                               phoneCall.setCellType(CellType.STRING);

                                socialRelations.setPhoneCall(phoneCall.getStringCellValue());
                            }
                            if (workCompany != null){
                                socialRelations.setWorkCompany(workCompany.getStringCellValue());
                            }
                            if (companyAddress != null){
                                socialRelations.setCompanyAddress(companyAddress.getStringCellValue());
                            }
                            if (homeAddress != null){
                                socialRelations.setHomeAddress(homeAddress.getStringCellValue());
                            }
                            if (remark != null){
                                socialRelations.setRemarks(remark.getStringCellValue());
                            }

                            socialRelations.setLastmodifyTime(new Date());
                            socialRelations.setRegisterTime(new Date());
                            int i= socialRelationsMapper.insert(socialRelations);
                            if (i > 0) {
                                baseWrapper.setFlag(true);
                                baseWrapper.setStatus(true);
                                baseWrapper.setMsg("导入成功");
                            }
                        }
                    }
                }
            }
        }
        return baseWrapper;
    }

    /**
     * 获取人事代码表
     * @param type
     * @return
     */
    public ToJson<HrCode> getHrCodes(String type) {
        ToJson<HrCode> toJson = new ToJson<>();
        List<HrCode> hrCodes=new ArrayList<>();
        HrCodeExample hrCodeExample=new HrCodeExample();
        HrCodeExample.Criteria criteria = hrCodeExample.createCriteria();
        hrCodeExample.setOrderByClause("cast(CODE_NO as SIGNED INTEGER) ASC");
        if ("relationship".equals(type)) { //与本人关系
            criteria.andParentNoEqualTo(RELATIONSHIP);
            hrCodes = hrCodeMapper.selectByExampleWithBLOBs(hrCodeExample);
        } else if ("politicalOutlook".equals(type)) {//政治面貌
            criteria.andParentNoEqualTo(POLITICAL_OUTLOOK);
            hrCodes=hrCodeMapper.selectByExampleWithBLOBs(hrCodeExample);
        }
        toJson.setMsg("ok");
        toJson.setFlag(0);
        toJson.setObject(hrCodes);
        return  toJson;
    }

    /**
     * 创建者：戚中校
     * 方法作用：根据条件查询数量
     * @param
     * @param deptId(传入的多个部门的编号)
     * @return 返回的json字符串中  nums是返回的结果的数量
     *
     */
    public ToJson<SocialRelations> selectNumByCon(SocialRelations record, Integer[] deptId) {
        ToJson toJson = new ToJson();
        try {
            Map<String, Object> map = new HashMap<String, Object>();
            if (deptId != null && deptId.length > 0){
                map.put("deptId",deptId);
            }
            map.put("record",record);
            List<SocialRelations> list = socialRelationsMapper.selectNumByCon(map);

            for(SocialRelations socialRelations :list){
                if(socialRelations.getRelationship() != null){
                    switch (socialRelations.getRelationship()){
                        case "1" : socialRelations.setRelationShipName("兄弟");break;
                        case "2" : socialRelations.setRelationShipName("姐妹");break;
                        case "3" : socialRelations.setRelationShipName("父子");break;
                        case "4" : socialRelations.setRelationShipName("母子");break;
                        case "5" : socialRelations.setRelationShipName("姐弟");break;
                        case "6" : socialRelations.setRelationShipName("兄妹");break;
                        case "7" : socialRelations.setRelationShipName("其它");break;
                        default:socialRelations.setRelationShipName("");break;
                    }
                }
                if(!StringUtils.checkNull(socialRelations.getPoliticalOutlook())){
                    if(socialRelations.getPoliticalOutlook().equals("1")){
                        socialRelations.setPoliticalOutlookName("群众");
                    }
                    else if(socialRelations.getPoliticalOutlook().equals("2")){
                        socialRelations.setPoliticalOutlookName("共青团员");
                    }
                    else if(socialRelations.getPoliticalOutlook().equals("3")){
                        socialRelations.setPoliticalOutlookName("中共党员");
                    }
                    else if(socialRelations.getPoliticalOutlook().equals("4")){
                        socialRelations.setPoliticalOutlookName("中共预备党员");
                    }
                    else if(socialRelations.getPoliticalOutlook().equals("5")){
                        socialRelations.setPoliticalOutlookName("民主党派");
                    }
                    else{
                        socialRelations.setPoliticalOutlookName("无党派人士");
                    }
                }
            }


            if(list.size() >= 0){
                toJson.setObj(list);
                toJson.setMsg("ok");
                toJson.setFlag(0);
            }else{
                toJson.setMsg("err");
                toJson.setFlag(1);
            }

        }catch (Exception e){
            toJson.setMsg("err");
            toJson.setFlag(1);
        }
        return toJson;
    }
    public ToJson<SocialRelationsWithBLOBs> getByStaffName(String staffName, Integer page, Integer pageSize, boolean useFlag){
        ToJson<SocialRelationsWithBLOBs> json=new ToJson<SocialRelationsWithBLOBs>();
        //分页
        PageParams pageParams = new PageParams();
        pageParams.setPage(page);
        pageParams.setPageSize(pageSize);
        pageParams.setUseFlag(useFlag);
        HashMap<String,Object> map = new HashMap();
        map.put("pageParams", pageParams);
        map.put("staffName",staffName);
        try{
            List<SocialRelationsWithBLOBs> list=socialRelationsMapper.getByStaffName(map);
            if(list.size()>0){
                for(SocialRelationsWithBLOBs socia:list){
                    if(socia.getStaffRole()!=null){
                        Users user = usersMapper.findUsersByuserId(socia.getStaffRole()); //根据 id 找名字
                        socia.setStaffRole(user.getUserName());
                    }
                    //与本人关系
                    HrCode hr_staff_contract2 = hrCodeMapper.selectCode("HR_STAFF_RELATIVES",socia.getRelationship());
                    if (hr_staff_contract2 != null) {
                        socia.setRelationShipName(hr_staff_contract2.getCodeName());
                    } else {
                        socia.setRelationShipName(" ");
                    }
                }
                json.setObj(list);
            }
            json.setTotleNum(socialRelationsMapper.getByStaffNameCount(staffName));
            json.setMsg("ok");
            json.setFlag(0);
        }catch (Exception e){
            e.printStackTrace();
            json.setMsg("err");
            json.setFlag(1);
        }
        return json;
    }
}
